# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

_realname=cliff
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=4.3.0
pkgrel=2
pkgdesc="Command Line Interface Formulation Framewor (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url='https://docs.openstack.org/cliff/latest/'
license=('spdx:Apache-2.0')
depends=("${MINGW_PACKAGE_PREFIX}-python-autopage"
         "${MINGW_PACKAGE_PREFIX}-python-cmd2"
         "${MINGW_PACKAGE_PREFIX}-python-importlib-metadata"
         "${MINGW_PACKAGE_PREFIX}-python-prettytable"
         "${MINGW_PACKAGE_PREFIX}-python-stevedore"
         "${MINGW_PACKAGE_PREFIX}-python-yaml")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-pbr"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python-wheel")
#checkdepends=("${MINGW_PACKAGE_PREFIX}-python-testrepository"
#              "${MINGW_PACKAGE_PREFIX}-python-mock"
#              "${MINGW_PACKAGE_PREFIX}-python-sphinx"
#              "${MINGW_PACKAGE_PREFIX}-python-oslosphinx"
#              "${MINGW_PACKAGE_PREFIX}-python-testscenarios")
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname/-/_}-${pkgver}.tar.gz")
sha256sums=('fc5b6ebc8fb815332770b2485ee36c09753937c37cce4f3227cdd4e10b33eacc')

# Helper macros to help make tasks easier #
apply_patch_with_msg() {
  for _patch in "$@"
  do
    msg2 "Applying $_patch"
    patch -Nbp1 -i "${srcdir}/$_patch"
  done
}

del_file_exists() {
  for _fname in "$@"
  do
    if [ -f $_fname ]; then
      rm -rf $_fname
    fi
  done
}
# =========================================== #

prepare() {
  rm -rf python-build-${MSYSTEM} | true
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}"

  # Set version for pbr
  export PBR_VERSION=${pkgver}
}

build() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

#check() {
#  msg "Python test for ${MSYSTEM}"
#  cd "${srcdir}/python-build-${MSYSTEM}"
#  PYTHON=${MINGW_PREFIX}/bin/python3 \
#     ${MINGW_PREFIX}/bin/python setup.py testr
#}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
